<template>
  <div class="details banxin">
    <p class="top">
      <span @click="$router.push(`/`)">首页</span>
      <span class="center" @click="$router.push(`/goods`)">全部商品</span>
      <span :class="{ active: $route.name == 'goodsdetail' }">商品详情</span>
    </p>
    <div class="content tanxin">
      <main class="tanxin">
        <div class="main_l">
          <div class="bigImg">
            <img
              width="100%"
              height="460"
              :src="'https://sc.wolfcode.cn' + productInfo.coverImg"
              alt=""
            />
          </div>
          <ul class="smallImg tanxin">
            <li
              @mouseenter="sClick(index, item.src)"
              :class="productActive === index ? 'active' : ''"
              v-for="(item, index) in productInfo.imgAltas"
              :key="index"
            >
              <img
                width="100%"
                :src="'https://sc.wolfcode.cn' + item.src"
                alt=""
              />
            </li>
          </ul>
        </div>
        <div class="main_r">
          <h2>{{ productInfo.seriesTitle }}</h2>
          <p>
            {{ productInfo.seriesSubTitle }}
          </p>
          <section>{{ productInfo.coin }}</section>
          <div v-for="(item, index) in productInfo.parameterJson" :key="index">
            <h3>{{ productInfo.parameterJson[0].title }}</h3>
            <ul>
              <li
                v-for="items in productInfo.parameterJson[0].parameters"
                :key="items.id"
                :class="{ active: items.currentActivate }"
                @click="getDatas(items.id)"
              >
                {{ items.title }}
              </li>
            </ul>
          </div>

          <h3>数量 <span>*礼品库存{{productInfo.stock}}件</span></h3>
          <div class="stepper tanxin">
            <div class="btn jia" @click="goodsnum(1)">+</div>
            <input type="text" v-model="stepNum" disabled />
            <div class="btn jian" @click="goodsnum(-1)">-</div>
          </div>
          <div class="btns">
            <div @click="addToCartFn">加入购物车</div>
            <div class="buynow">立即购买</div>
          </div>
        </div>
      </main>
      <div class="cebian">
        <span class="cebian_1">你还可以兑换</span>
        <ul class="nei_1">
          <li
            class="img_1"
            v-for="(item, index) in themYouCanBuy"
            :key="index"
            @click="getDatas(item.id)"
          >
            <img
              height="60"
              :src="'https://sc.wolfcode.cn' + item.img"
              alt=""
            />
            <div class="nei_2">
              <span class="nei_3">{{ item.name }}</span>
              <br />
              <span class="nei_4">{{ item.coin }}</span>
            </div>
          </li>
        </ul>
      </div>
    </div>
    <div class="jieshao banxin">
      <ul class="jieshao_1">
        <li :class="{ active: productNum == 1 }" @click="productNum = 1">
          商品详情
        </li>
        <li :class="{ active: productNum == 0 }" @click="productNum = 0">
          联系我们
        </li>
      </ul>
      <div ref="miaoshu" class="descriptionImg" v-show="productNum == 1">
      </div>
      <div class="lianxi_1" v-show="productNum == 0">
        <h3>兑换后运费如何收取？</h3>
        <p>
          商城内大部分实物产品均可包邮，也支持上门自提。虚拟产品则无需运费，可在兑换后直接使用。
        </p>
        <p>
          （注：新疆，西藏，内蒙古，青海，海南，宁夏暂不支持包邮，在此地区兑换商品需提前与客服确认运费。）
        </p>
        <p>

        <h3>如何申请退换货？</h3>
        <p>所有产品均为鸡腿兑换礼，无质量问题不支持退换货；</p>
        <p>如因喜好不同，或到货后后悔等原因，不支持退货；</p>
        <p>
          因客户原因如联系方式有误、电话停机、不接电话、无理由拒收等造成快件无法正常签收的情况，叩丁狼均不进行补发或赔付；
        </p>
        <p>
          如因质量问题需要退货，将由客服人员与客户联系，确认邮寄地址与流程。退回物品不得有人为损坏或使用痕迹，否则拒绝退换；
        </p>
        <p>
          如顾客选择自行寄回商品，请先垫付运费，到货验证商品后，叩丁狼将以鸡腿发放形式为用户报销运费，不接受单方面到付件。
        </p>
        <h3>如何开具发票？</h3>
        <p>叩丁狼积分商城产品均为定制礼品，使用积分兑换的产品均不支持开票。</p>
        <h3>关于鸡腿价格问题</h3>
        <p>
          因可能存在系统缓存、页面更新延迟等不确定性情况，导致价格显示异常，商品具体售价请以订单结算页价格为准。如您发现异常情况出现，请立即联系我们补正，以便您能顺兑换。
        </p>

        <h3>联系我们</h3>
        <p><a href="https://www.wolfcode.cn/" class="wolf">www.wolfcode.cn</a></p>
        <p>微信公众号搜索“叩丁狼”</p>
      </div>
    </div>
  </div>
</template>
  
<script>
import { GoodsDetailsApi, GetgoodsApi } from "@/request/api";
export default {
  data() {
    return {
      stepNum: 1,
      // 小图的当前项
      productActive: 0,
      // 产品信息
      productInfo: {
        coverImg: "",
      },
      themYouCanBuy: {},
      productNum: 1,
      description: {},
      // 当前商品的id
      getGoodsid: 0,
    };
  },
  methods: {
    goodsnum(num) {
      if (num == -1 && this.stepNum == 1) {
        return;
      }
      this.stepNum += num;
      if (this.stepNum > 5 && num == 1) {
        this.$store.dispatch("AsyncToast", {
          value: "最多买五个",
          icon: "danger",
        });
        this.stepNum--;
        return;
      }
    },
    //   点击小图 大图跟着变
    sClick(index, src) {
      this.productActive = index;
      this.productInfo.coverImg = src;
    },
    // addToCartFn() {
    //   AddToCartApi({
    //     productId: this.productInfo.id,
    //     total: this.stepNum,
    //   }).then((res) => {
    //     if (res.data.code === 0) {
    //       let obj = { content: "已成功添加到购物车", icon: "success" };
    //       this.$store.dispatch("AsyncToast", obj);
    //     } else {
    //       let obj = { content: "res.data.message", icon: "info" };
    //       this.$store.dispatch("AsyncToast", obj);
    //     }
    //   });
    // },
    getDatas(id) {
      this.getGoodsid = id;
      GoodsDetailsApi(id).then((res) => {
        if (res.data.code === 0) {
          
          let { productInfo, themYouCanBuy } = res.data.data;
          this.productInfo = productInfo;
          console.log(productInfo.stock);
          this.description = productInfo.description.replace(
            /upload/g,
            "http://sc.wolfcode.cn/upload"
          );
          this.themYouCanBuy = themYouCanBuy;
          this.$refs.miaoshu.innerHTML = this.description;
          
        }
      });
    },
    addToCartFn() {
      if (this.$store.state.myChicken === "--") {
        this.$store.dispatch("AsyncToast", {
          value: "请先登录",
          icon: "danger",
        });
      } else {
        GetgoodsApi({
          productId: this.productInfo.id,
          total: this.stepNum,
        }).then((res) => {
          this.$store.dispatch("AsyncToast", {
            value: "加入购物车成功",
            icon: "success",
          });
        });
      }
    },
  },
  created() {
    this.getDatas(this.$route.params.id);
  },
};
</script>
   
<style lang = "less" scoped>
@import "@/assets/base.less";
.top {
  cursor: pointer;
  margin: 30px 0;
  color: #ccc;
  .center {
    margin: 0 30px;
  }
  .active {
    font-weight: 700;
    color: @black;
  }
}
.content {
  min-height: 560px;
  main {
    width: 970px;
    /* background: pink; */
    border-right: 3px solid #ccc;
    box-sizing: border-box;
    padding-right: 49px;
    .main_l {
      width: 459px;
      margin-right: 32px;
      .bigImg {
        width: 459px;
        height: 460px;
        margin-bottom: 21px;
        img {
          display: block;
        }
      }
      .smallImg {
        width: 459px;
        li {
          width: 100px;
          height: 100px;
          opacity: 0.6;
          box-sizing: border-box;
          &.active {
            opacity: 1;
            border: 2px solid red;
          }
        }
      }
    }
    .main_r {
      flex: 1;
      /* background: tan; */
      h2 {
        font-size: 28px;
        color: @black;
      }
      p {
        margin-top: 15px;
        font-size: 14px;
        color: #999999;
        line-height: 1.2;
        margin-bottom: 26px;
      }
      section {
        font-size: 28px;
        font-weight: bold;
        color: #fd604d;
        padding-bottom: 23px;
        border-bottom: 1px solid #ccc;
      }
      h3 {
        margin-top: 19px;
        margin-bottom: 14px;
        font-size: 16px;
        color: @black;
        font-weight: bold;
        span{
          color: #ccc;
          font-size: 12px;
          margin-left: 10px;
        }
      }
      ul {
        display: flex;
        flex-wrap: wrap;
        li {
          height: 32px;
          border: 1px solid #d1d1d1;
          color: #666666;
          line-height: 32px;
          padding: 0 17px;
          cursor: pointer;
          margin-right: 20px;
          margin-bottom: 11px;
          &.active {
            color: @blue;
            border-color: @blue;
          }
        }
      }
      .stepper {
        background: #fff;
        width: 105px;
        .btn {
          width: 30px;
          height: 32px;
          border: 1px solid #d1d1d1;
          text-align: center;
          box-sizing: border-box;
          line-height: 32px;
          color: #ccc;
          cursor: pointer;
        }
        input {
          width: 45px;
          border: 0;
          box-sizing: border-box;
          text-align: center;
          border-top: 1px solid #ccc;
          border-bottom: 1px solid #ccc;
        }
      }
      .btns {
        display: flex;
        margin-top: 24px;
        div {
          width: 150px;
          height: 46px;
          background: #3dc36b;
          font-size: 18px;
          color: #ffffff;
          line-height: 46px;
          text-align: center;
          cursor: pointer;
          margin-right: 19px;
          &.buynow {
            background: @orange;
          }
        }
      }
    }
  }
  .cebian {
    // background-color: pink;
    width: 300px;
    margin-left: 20px;
    overflow: hidden;
    .cebian_1 {
      font-size: 18px;
      font-family: SourceHanSansSC;
      font-weight: 400;
      color: @black;
      line-height: 20px;
    }
    .nei_1 {
      margin-top: 30px;
      float: left;
      .img_1 {
        margin-bottom: 20px;
      }
    }
    .nei_2 {
      width: 150px;
      height: 60px;
      float: right;
      .nei_3 {
        display: block;
        margin: 4px 0;

        font-size: 14px;
        font-family: SourceHanSansSC;
        font-weight: 300;
        color: @blue;
        line-height: 20px;
      }
      .nei_4 {
        display: block;
        margin: -4px 0;
        font-size: 18px;
        font-family: SourceHanSansSC;
        font-weight: bold;
        color: #ff5e0f;
        line-height: 20px;
      }
    }
  }
}
.jieshao {
  // height: 100px;
  // width: 300px;
  // height: 300px;
  // background-color: pink;
  .jieshao_1 {
    display: flex;
  }
  li {
    width: 120px;
    height: 50px;
    cursor: pointer;
    margin-top: 50px;
    background: #ececec;
    line-height: 50px;
    display: inline-block;
    text-align: center;
    font-weight: bold;
    &.active {
      color: white;
      background-color: @blue;
    }
  }
  .lianxi {
    margin-top: 50px;
    margin-left: 30px;
    line-height: 50px;
    display: inline-block;
    text-align: center;
    font-weight: bold;
  }
  .p1 {
    margin-top: 30px;
    color: #999;
  }
}
.lianxi_1 {
  h3 {
    font-size: 18px;
    font-weight: 700;
    margin-top: 10px;
    margin-bottom: 10px;
  }
  p {
    color: @black;
    font-size: 18px;
    line-height: 2;
    font-weight: 200;
  }
  a.wolf{
    color: @black;
    text-decoration: none;
  }
}
</style>